package com.blast.apply.ui

import android.view.KeyEvent
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.blast.apply.R
import com.blast.apply.adapter.AuthDetailAdapter
import com.wxl.common.base.AbsActivity
import com.wxl.common.room.entity.UnApplyBlastEntity
import com.wxl.common.util.LayoutHelper
import com.wxl.common.util.ObservableUtil
import kotlinx.android.synthetic.main.activity_auth_detail_layout.*

class UnAuthDetailActivity : AbsActivity() {

    var lgs: ArrayList<UnApplyBlastEntity.LgsBean.LgBean>? = null
    var lanlat: String? = null
    var mAuthDetailAdapter: AuthDetailAdapter? = null

    override fun getCreateContentViewId(): Int {
        return R.layout.activity_auth_detail_layout
    }

    override fun onCreateViewChanged() {
        setTopTitle("详情")
        lgs = intent.getSerializableExtra("lgs") as ArrayList<UnApplyBlastEntity.LgsBean.LgBean>?
        val p = intent.getIntExtra("position",0)
        lanlat = intent.getStringExtra("lanlat")
        lgs?.let {
            mAuthDetailAdapter = AuthDetailAdapter(lgs,p,lanlat)
            authDetailListView.layoutManager = LinearLayoutManager(this)
            LayoutHelper.getDetonatorTitleViewsWidth(unAuthDetailTitleLayout,object : ObservableUtil.Companion.OnNextCallback<ArrayList<Int>>(){
                override fun onNext(t: ArrayList<Int>) {
                    mAuthDetailAdapter?.setWidths(t)
                    mAuthDetailAdapter?.bindToRecyclerView(authDetailListView)
                }
            })
        }

        authDetailBackBtn.setOnClickListener {
            finish()
        }

        authDetailApplyBtn.visibility = View.INVISIBLE
    }

    override fun onKeyDownEvent(keyCode: Int, event: KeyEvent?): Boolean {
        mAuthDetailAdapter?.onKeyDown(keyCode,event)
        if(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_F1){
            authDetailBackBtn.performClick()
        }
        return true
    }

    override fun addTitleSwitcher(): Boolean {
        return false
    }

}